package no.sachmuld.methodcombination.impl;

import no.sachmuld.methodcombination.api.Condition;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class MultiCondition extends Condition {

    private List<Condition> conditions;
    private char catChar;

    public MultiCondition(List<Condition> conditions, char catChar) {
        this.conditions = conditions;
        this.catChar = catChar;
    }

    @Override
    public List<Clause> getFailures() {
        List<Clause> failures = new ArrayList<>();
        for (Condition condition : conditions) {
            if (!condition.getValue()) {
                failures.addAll(condition.getFailures());
            }
        }
        return failures;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < conditions.size(); i++) {
            if (i > 0) {
                sb.append(" ");
                sb.append(catChar);
                sb.append(" ");
            }
            sb.append(conditions.get(i).toString());
        }
        return sb.toString();
    }

}
